/*
 * Copyright (C) 2018 Zhejiang xiaominfo Technology CO.,LTD.
 * All rights reserved.
 * Official Web Site: http://www.xiaominfo.com.
 * Developer Web Site: http://open.xiaominfo.com.
 */

package com.xiaominfo.oss.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaominfo.oss.common.pojo.Pagination;
import com.xiaominfo.oss.module.dao.OSSAppInfoMapper;
import com.xiaominfo.oss.module.model.OSSAppInfo;
import com.xiaominfo.oss.module.model.OSSDeveloper;
import com.xiaominfo.oss.service.OSSAppInfoService;
import com.xiaominfo.oss.utils.PaginationUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/***
 *
 * @since:oss-server 1.0
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a> 
 * 2018/06/17 19:53
 */
@Service
public class OSSAppInfoServiceImpl extends ServiceImpl<OSSAppInfoMapper,OSSAppInfo> implements OSSAppInfoService {

    @Resource
    OSSAppInfoMapper ossAppInfoMapper;

    @Override
    public Pagination<OSSAppInfo> queryByPage(OSSAppInfo ossAppInfo, Integer current_page, Integer page_size) {

        QueryWrapper<OSSAppInfo> wrapper=new QueryWrapper<>();
        Integer count=ossAppInfoMapper.selectCount(new QueryWrapper<>());
        RowBounds bounds = PaginationUtils.getBounds(current_page, page_size);
        Page page = new Page((long) Convert.toInt(current_page, 1), (long)Convert.toInt(page_size, 10));

        Page page1 = ossAppInfoMapper.selectPage(page, wrapper);
        Pagination<OSSAppInfo> pagination=PaginationUtils.transfor(page1.getRecords(),Convert.toInt(page.getTotal()),current_page,page_size);
        return pagination;
    }

    @Override
    public Integer queryByCode(String code) {
        QueryWrapper<OSSAppInfo> wrapper=new QueryWrapper<>();
        wrapper.eq("code",code);
        Integer list=ossAppInfoMapper.selectCount(wrapper);
        return list;
    }

    @Override
    public List<OSSAppInfo> queryByDevIds(String devId) {
        QueryWrapper<OSSAppInfo> wrapper=new QueryWrapper<>();
        wrapper.eq("dev_id",devId);
        return ossAppInfoMapper.selectList(wrapper);
    }
}
